package com.erp.products.productlist.service.impl;

import com.erp.common.utils.oss.AliyunOSSConstants;
import com.erp.products.productlist.domain.ErpProducts;
import com.erp.products.productlist.mapper.ProductListMapper;
import com.erp.products.productlist.service.ProductListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductListServiceImpl implements ProductListService {
    @Autowired
    private ProductListMapper productListMapper;


    // 查询所有商品
    @Override
    public List<ErpProducts> list(ErpProducts erpProducts) {
        List<ErpProducts> list = productListMapper.list(erpProducts);
        //遍历集合,将image前面添加AliyunOSSConstants.COMMON_URL
        list.forEach(item -> {
            item.setProductImage(AliyunOSSConstants.COMMON_URL + item.getProductImage());
        });
        return list;
    }

    // 根据id查询商品
    public ErpProducts selectErpProductsById(Long productId)
    {
        return productListMapper.selectErpProductsById(productId);
    }

    @Override
    public int deleteErpProductsById(Long productId) {
        return productListMapper.deleteErpProductsById(productId);
    }

    @Override
    public int updateErpProducts(ErpProducts erpProducts) {
        return productListMapper.updateErpProducts(erpProducts);
    }

    // 批量插入
    public void insertBatch(List<ErpProducts> cachedDataList) {
        productListMapper.insertBatch(cachedDataList);
    }
}
